#include <iostream>
#include <future>
#include <chrono>
#include <thread>
#include <memory>
using namespace std;
int Add(int num1, int num2)
{
    cout << "int Add1(int num1, int num2)" << endl;
    this_thread::sleep_for(chrono::seconds(5));
    cout << "int Add2(int num1, int num2)" << endl;
    return num1 + num2;
}
int main()
{
    // 异步同时执行
    //  packaged_task<int(int, int)> task(Add);
    //  future<int> fut = task.get_future();
    auto task = make_shared<packaged_task<int(int, int)>>(Add);
    cout << "----------------------1----------------------" << endl;
    thread th([task]()
              { (*task)(11, 22); });
    future<int> fut = task->get_future();
    this_thread::sleep_for(chrono::seconds(3));
    cout << "----------------------2----------------------" << endl;
    int ret = fut.get();
    cout << ret << endl;
    cout << "----------------------3----------------------" << endl;
    th.join();
    return 0;
}